<template >
 
  <div class="login-container">
      <el-card class="login-card">
          <h2 class="login-title">用户登录</h2>
          <el-form :model="logininfo" ref="loginrule"  label-width="auto"  >
              <el-form-item label="账号" prop="loginname" >
                  <el-input v-model="logininfo.LoginName"></el-input>
              </el-form-item>
              <el-form-item label="密码" prop="password">
                  <el-input type="password" v-model="logininfo.LoginPwd"></el-input>
              </el-form-item>
              <el-form-item>
                <div class="login-button">
                  <el-button type="primary" @click="Login">登录</el-button>
                  <el-button @click="goToRegister">注册</el-button>
                </div>
              </el-form-item>
              
          </el-form>
      </el-card>
      <div class="beij"></div>
  </div>

</template>

<script setup>
import { reactive, ref } from 'vue';
import { useRouter } from 'vue-router';
import { ElMessage } from 'element-plus';
import loginapi from '../api/loginapi';
import {useMainStore} from "../stores/index"

const logininfo=reactive({
  LoginPwd:"",
    LoginName:""

})

const rules = {
  LoginName: [{ required: true, message: '请输入账号', trigger: 'blur' }],
  LoginPwd: [{ required: true, message: '请输入密码', trigger: 'blur' }],
};

const router = useRouter();
var Photo=useMainStore();
const Login = () => {
  
  loginapi.Login(logininfo).then(res=>{
			console.log("login.res", res.data);
      console.log("token",res.data.auth.token)
			sessionStorage.setItem("token",res.data.auth.token)		
			 Photo.setProfilePhoto("http://localhost:5242/"+res.data.ProfilePhoto);			 
			router.push({
				path: '/welcome'
			})
  }).catch(err => {
			console.log("err=>", err);
		})
  
};

const goToRegister = () => {
  router.push('/register');
};
</script>

<style scoped>
.login-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: calc(100vh - 16px);
}
.login-card {
  background-color: rgba(255, 255, 255, 0.8);
  width:20%;
}
.login-title{
  text-align: center;
}
.login-button{
  width: 100%;
  display: flex;
  justify-content: center;
}
.beij{
  width: 100%;
  height: 100vh;
  background: url('../images/zhuye.png') center center no-repeat;
  background-size: 100% 100%;
  position:absolute;
  backface-visibility: visible;
  z-index: -1;
  }
</style>